import { chromium } from 'playwright';
import { writeFileSync } from 'fs';

const [, , url = 'https://www.baidu.com'] = process.argv;

(async () => {
  const browser = await chromium.launch({ headless: true });
  const page    = await browser.newPage();
  await page.goto(url, { waitUntil: 'networkidle' }); // 等网络空闲
  const html = await page.content();                  // 包含 JS 执行后的完整 DOM
  writeFileSync('source.html', html);
  console.log('已保存到 source.html');
  await browser.close();
})();